<#assign ctx=springMacroRequestContext.contextPath />
<!DOCTYPE html>
<html>
<head>
  <title>登录斯兔权限系统</title>
  <meta charset="utf-8"/>
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="${ctx}/common/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="${ctx}/common/css/admin.css" media="all">
  <link rel="stylesheet" href="${ctx}/common/module/dtree/dtree.css">
  <link rel="stylesheet" href="${ctx}/common/module/dtree/font/dtreefont.css">
  <link rel="stylesheet" href="${ctx}/common/module/soultable/soulTable.css">
  <link rel="stylesheet" href="${ctx}/common/module/soultable/animate.min.css">
  <style>
    .layui-table-cell {
      /*height: auto !important;*/
      /*overflow: visible;*/
      /*text-overflow: inherit;*/
      /*white-space: normal;*/
    }
  </style>
</head>
<body>
<div class="layui-fluid">
  <div class="layui-row layui-col-space15">
    <div class="layui-col-sm12 layui-col-md12 layui-col-lg12">
      <div class="layui-card">
        <div class="layui-card-body">
          <!--<div class="layui-form toolbar">-->
          <!--  <div class="layui-form-item">-->
          <!--    <div class="layui-inline">-->
          <!--      <input id="roleName" class="layui-input layui-input-inline" type="text" placeholder="角色名称"/>-->
          <!--    </div>-->
          <!--    <div class="layui-inline">-->
          <!--      <button id="btnSearch" class="layui-btn layui-btn-radius layui-btn-sm icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>-->
          <!--      <button id="btnExp" class="layui-btn layui-btn-radius layui-btn-sm icon-btn"><i class="layui-icon">&#xe67d;</i>导出</button>-->
          <!--    </div>-->
          <!--  </div>-->
          <!--</div>-->
          <table id="tableStdchkItem" lay-filter="tableStdchkItem"></table>
        </div>
      </div>
    </div>
  </div>
</div>
<script type="text/html" id="tableToolBar">
  <@shiro.hasPermission name="sysrole/add">
  <a class="layui-btn layui-btn-normal layui-btn-sm layui-btn-radius" lay-event="add"><i class="layui-icon">&#xe654;</i>添加</a>
  </@shiro.hasPermission>
  <@shiro.hasPermission name="sysrole/edit">
  <a class="layui-btn layui-btn-normal layui-btn-sm layui-btn-radius" lay-event="edit"><i class="layui-icon">&#xe642;</i>修改</a>
  </@shiro.hasPermission>
  <@shiro.hasPermission name="sysrole/delete">
  <a class="layui-btn layui-btn-danger layui-btn-sm layui-btn-radius" lay-event="del"><i class="layui-icon">&#xe640;</i>删除</a>
  </@shiro.hasPermission>
  <a class="layui-btn layui-btn-danger layui-btn-sm layui-btn-radius" lay-event="importFile"><i class="layui-icon">&#xe640;</i>导入</a>
</script>
<script src="${ctx}/common/plugins/jquery/jquery-1.11.2.min.js"></script>
<script src="${ctx}/common/layui/layui.js"></script>
<script>
    layui.config({
        base: '${ctx}/common/module/' //此处路径请自行处理, 可以使用绝对路径
    }).extend({
        formSelects: 'formSelects/formSelects-v4',
        dtree: '{/}${ctx}/common/module/dtree/dtree',
        treetable: '{/}${ctx}/common/module/treetable-lay/treetable',
        soulTable: '{/}${ctx}/common/module/soultable/soulTable',
        tableFilter: '{/}${ctx}/common/module/soultable/tableFilter',
        excel: '{/}${ctx}/common/module/soultable/excel',
        tableChild: '{/}${ctx}/common/module/soultable/tableChild',
        tableMerge: '{/}${ctx}/common/module/soultable/tableMerge',
    });
    layui.use(['layer', 'form', 'table','upload', 'formSelects', 'dtree', 'treetable', 'soulTable', 'tableFilter', 'excel', 'tableChild', 'tableMerge'], function () {
        var table = layui.table;
        //var element = layui.element;
        table.render({
            elem: "#tableStdchkItem",
            id: 'tableStdchkItem',
            url: "${ctx}/risksource/index",
            method: "post",
            request: {
                limitName: 'pageSize'
            },
            page: true,
            //skin: 'line',
            //even: true, //开启隔行背景
            size: 'sm', //小尺寸的表格
            limit: '1000',
            limits:[10,20,30,40,50,100,200,300,500,1000],
            toolbar: '#tableToolBar',
            loading: true,
            height: 'full-40',
            cellMinWidth: 100,
            parseData: function (res) {
                return {
                    "code": 0, //解析接口状态
                    "msg": '', //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.records //解析数据列表
                }
            },
            cols: [[
                {type: 'radio'},
                {
                    field: "catgoryname",
                    title: '分类', filter: true, sort: true,
                    width: 100, merge: true,
                },
                {
                    field: "levelname",
                    title: '等级', sort: true,
                    width: 100, merge: true, filter: true
                    //templet: function (d) {
                    //    return '<div><span title="d.demand">' + d.demand + '</span></div>'
                    //}
                },
                {
                    field: "description",
                    title: '风险源描述', sort: true,
                    width: 300,
                },
                {
                    field: "measures",
                    title: '常规措施',
                    align: 'center',
                },
                {
                    field: "possibility",
                    title: '可能性',
                    align: 'center',
                },
                {
                    field: "exposure_rate",
                    title: '暴露率',
                    align: 'center',
                },
                {
                    field: "consequences",
                    title: '后果',
                    align: 'center',
                },
                {
                    field: "risk_value",
                    title: '风险值',
                    align: 'center',
                },
                {
                    field: "risk_flag",
                    title: '风险最大标示',
                    align: 'center',
                },
                {field: "", title: '操作', toolbar: "#operation", width: 220, align: 'center', hide: true},
            ]],
            filter: {
                items: ['column', 'data', 'condition', 'editCondition', 'excel', 'clearCache'] // 加入了清除缓存按钮
                , cache: true
            },
            done: function (res, curr, count) {
                layui.soulTable.render(this);
            }
        })
        table.on('toolbar(tableStdchkItem)', function (obj) {
            //console.log(obj);
            var data = table.checkStatus(obj.config.id).data[0];
            //console.log(data);
            if (obj.event == 'add') {
                $.get("${ctx}/risksource/add", {}, function (str) {
                    var indexlayer = layui.layer.open({
                        title: "添加",
                        offset: 't',
                        area: ['530px', '500px'],
                        shadeClose: true,
                        type: 1,
                        anim: 2,
                        resize: false,
                        btn: ['保存', '取消'],
                        content: str,
                        yes: function (index, layero) {
                            //return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
                            var data = $("#roleForm").serializeObject();
                            //var param = dtree.getNowParam("parentIdTree");
                            var params = dtree.getCheckbarNodesParam("parentIdTree");
                            console.log(params);
                            var menuIds = [];
                            $.each(params, function (index, item) {
                                menuIds.push(item.nodeId);
                            });
                            data.menuIds = menuIds;
                            $.ajax({
                                async: true,//默认true为异步
                                url: '${ctx}/sysrole/add',
                                type: "post",
                                data: data,
                                dataType: "json",
                                beforeSend: function (xhr) {
                                },
                                success: function (res, status, xhr) {
                                    if (res.code == 200) {
                                        table.reload('tableStdchkItem', {});
                                        layui.layer.close(indexlayer);
                                    } else {
                                        layer.msg('更新失败！请重试！');
                                    }
                                },
                                error: function (xhr, status, error) {
                                }
                            });
                        },
                        success: function (layero, index) {
                        },
                        btn2: function (index, layero) {
                            //按钮【按钮二】的回调
                            //return false 开启该代码可禁止点击该按钮关闭
                        },
                        btn3: function (index, layero) {
                            //按钮【按钮三】的回调
                            //return false 开启该代码可禁止点击该按钮关闭
                        },
                        cancel: function () {
                            //右上角关闭回调
                            //return false 开启该代码可禁止点击该按钮关闭
                        }
                    })
                });
            }
            if (obj.event == 'del') {
                if (data != null) {
                    layui.layer.confirm('确定删除此信息？', {icon: 2, title: '提示信息'}, function (index) {
                        $.ajax({
                            type: "post",
                            url: '${ctx}/risksource/delete',
                            data: {'id': data.id},
                            dataType: 'json',
                            success: function (d) {
                                layui.layer.msg("删除成功");
                                table.reload('tableStdchkItem', {});
                            }
                        })
                        layer.close(index);
                    });
                } else {
                    layer.msg('请勾选记录！');
                }
            }
            if (obj.event == 'edit') {
                if (data != null) {
                    $.get("${ctx}/risksource/edit", {"id": data.id}, function (str) {
                        var indexlayer = layui.layer.open({
                            title: "修改",
                            offset: 't',
                            area: ['530px', '500px'],
                            shadeClose: true,
                            type: 1,
                            anim: 2,
                            resize: false,
                            btn: ['保存', '取消'],
                            content: str,
                            yes: function (index, layero) {
                                //return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
                                var data = $("#roleForm").serializeObject();
                                //var param = dtree.getNowParam("parentIdTree");
                                var params = dtree.getCheckbarNodesParam("parentIdTree");
                                console.log(params);
                                var menuIds = [];
                                $.each(params, function (index, item) {
                                    menuIds.push(item.nodeId);
                                });
                                data.menuIds = menuIds;
                                $.ajax({
                                    async: true,//默认true为异步
                                    url: '${ctx}/sysrole/edit',
                                    type: "post",
                                    data: data,
                                    dataType: "json",
                                    beforeSend: function (xhr) {
                                    },
                                    success: function (res, status, xhr) {
                                        if (res.code == 200) {
                                            table.reload('tableStdchkItem', {});
                                            layui.layer.close(indexlayer);
                                        } else {
                                            layer.msg('更新失败！请重试！');
                                        }
                                    },
                                    error: function (xhr, status, error) {
                                    }
                                });
                            },
                            success: function (layero, index) {
                            },
                            btn2: function (index, layero) {
                                //按钮【按钮二】的回调
                                //return false 开启该代码可禁止点击该按钮关闭
                            },
                            btn3: function (index, layero) {
                                //按钮【按钮三】的回调
                                //return false 开启该代码可禁止点击该按钮关闭
                            },
                            cancel: function () {
                                //右上角关闭回调
                                //return false 开启该代码可禁止点击该按钮关闭
                            }
                        })
                    });
                } else {
                    layer.msg('请勾选记录！');
                }
            }
            if (obj.event == 'importFile') {
                $.get("../page/risksource/risksource_import.html", {}, function (str) {
                    var indexlayer = layui.layer.open({
                        title: "添加",
                        offset: 't',
                        area: ['530px', '500px'],
                        shadeClose: true,
                        type: 1,
                        anim: 2,
                        resize: false,
                        btn: ['保存', '取消'],
                        content: str,
                        yes: function (index, layero) {
                            //return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
                            var data = $("#roleForm").serializeObject();
                            //var param = dtree.getNowParam("parentIdTree");
                            var params = dtree.getCheckbarNodesParam("parentIdTree");
                            console.log(params);
                            var menuIds = [];
                            $.each(params, function (index, item) {
                                menuIds.push(item.nodeId);
                            });
                            data.menuIds = menuIds;
                            $.ajax({
                                async: true,//默认true为异步
                                url: '${ctx}/sysrole/add',
                                type: "post",
                                data: data,
                                dataType: "json",
                                beforeSend: function (xhr) {
                                },
                                success: function (res, status, xhr) {
                                    if (res.code == 200) {
                                        table.reload('tableStdchkItem', {});
                                        layui.layer.close(indexlayer);
                                    } else {
                                        layer.msg('更新失败！请重试！');
                                    }
                                },
                                error: function (xhr, status, error) {
                                }
                            });
                        },
                        success: function (layero, index) {
                        },
                        btn2: function (index, layero) {
                            //按钮【按钮二】的回调
                            //return false 开启该代码可禁止点击该按钮关闭
                        },
                        btn3: function (index, layero) {
                            //按钮【按钮三】的回调
                            //return false 开启该代码可禁止点击该按钮关闭
                        },
                        cancel: function () {
                            //右上角关闭回调
                            //return false 开启该代码可禁止点击该按钮关闭
                        }
                    })
                });
            }
        });
    });
</script>
</body>
</html>